package com.sky.edumanageapi.comment.controller;

import com.sky.edumanageapi.base.response.JsonResult;
import com.sky.edumanageapi.comment.pojo.dto.CommentParam;
import com.sky.edumanageapi.comment.pojo.vo.CommentVO;
import com.sky.edumanageapi.comment.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "评论模块")
@RestController
@RequestMapping("/api/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("发表评论")
    @PostMapping("create")
    public JsonResult createComment(@RequestBody CommentParam commentParam){

        log.debug("发表评论传入参数:{}",commentParam);

        commentService.insert(commentParam);

        return JsonResult.ok();
    }

    @ApiOperation("根据课程获取课程评论")
    @GetMapping("list/course/{courseId}")
    public JsonResult getCommentListByCourseId(@PathVariable Integer courseId){

        log.debug("获取课程评论,课程Id:{}",courseId);

        List<CommentVO> commentVOList = commentService.getCommentListByCourseId(courseId);

        return JsonResult.ok(commentVOList);
    }

    @ApiOperation("根据用户获取课程评论")
    @GetMapping("list/user/{userId}")
    public JsonResult getCommentListByUserId(@PathVariable Integer userId){

        log.debug("获取课程评论,课程Id:{}",userId);

        List<CommentVO> commentVOList = commentService.getCommentListByUserId(userId);

        return JsonResult.ok(commentVOList);
    }
}
